package org.inspiration.dudu.web.controller.user;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.inspiration.dudu.common.pojo.Result;
import org.inspiration.dudu.user.model.dto.FavoriteFolderDTO;
import org.inspiration.dudu.user.model.vo.FavoriteFolderVO;
import org.inspiration.dudu.web.annotation.Loggable;
import org.inspiration.dudu.web.service.user.FavoriteFolderFacadeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/favorite-folders")
@Tag(name = "收藏夹接口", description = "提供与用户收藏夹相关的操作接口")
@RequiredArgsConstructor
@Loggable

public class FavoriteFolderController {
    private final FavoriteFolderFacadeService favoriteFolderFacadeService;

    @PostMapping
    @Operation(summary = "创建收藏夹", description = "接收收藏夹数据并创建新的收藏夹")
    public Result<Void> createFavoriteFolder(@RequestBody FavoriteFolderDTO favoriteFolderDTO) {
        // 创建收藏夹
        favoriteFolderFacadeService.createFavoriteFolder(favoriteFolderDTO);
        return Result.success();
    }

    @DeleteMapping
    @Operation(summary = "删除收藏夹", description = "根据收藏夹数据删除指定的收藏夹")
    public Result<Void> deleteFavoriteFolder(@RequestBody FavoriteFolderDTO favoriteFolderDTO) {
        // 删除收藏夹
        favoriteFolderFacadeService.deleteFavoriteFolder(favoriteFolderDTO);
        return Result.success();
    }

    @GetMapping("/{userId}")
    @Operation(summary = "获取所有收藏夹", description = "根据用户ID获取该用户的所有收藏夹")
    public Result<List<FavoriteFolderVO>> getAllFavoriteFolders(@PathVariable("userId") Long userId) {
        List<FavoriteFolderVO> list = favoriteFolderFacadeService.getAllFavoriteFolders(userId);
        return Result.success(list);
    }

}
